import Mock from 'mockjs';

// 小说相关
Mock.mock(/\/novel\/list/, 'get', {
  code: 200,
  message: 'success',
  data: {
    'list|10': [{
      'id|+1': 1,
      'name': '@ctitle(3, 10)',
      'authorName': '@cname',
      'authorId|1-100': 1,
      'categoryName': '@pick(["玄幻", "修真", "都市", "历史"])',
      'categoryId|1-4': 1,
      'cover': '@image("200x300")',
      'status|1': ['serializing', 'completed'],
      'wordCount|10000-1000000': 1,
      'updateTime': '@datetime'
    }],
    'total': 100
  }
});

// 分类列表（带分页）
Mock.mock(/\/category\/list\?.*/, 'get', {
  code: 200,
  message: 'success',
  data: {
    'list|10': [{
      'id|+1': 1,
      'name': '@pick(["玄幻", "修真", "都市", "历史", "科幻", "奇幻", "武侠", "仙侠", "游戏", "体育"])',
      'novelCount|0-100': 1,
      'sort|1-100': 1,
      'description': '@cparagraph(1, 2)',
      'createTime': '@datetime'
    }],
    'total': 100
  }
});

// 分类列表（不分页，用于下拉选择）
Mock.mock(/\/category\/list$/, 'get', {
  code: 200,
  message: 'success',
  data: [
    { id: 1, name: '玄幻' },
    { id: 2, name: '修真' },
    { id: 3, name: '都市' },
    { id: 4, name: '历史' },
    { id: 5, name: '科幻' },
    { id: 6, name: '奇幻' },
    { id: 7, name: '武侠' },
    { id: 8, name: '仙侠' },
    { id: 9, name: '游戏' },
    { id: 10, name: '体育' }
  ]
});

// 作者列表（带分页）
Mock.mock(/\/author\/list\?.*/, 'get', {
  code: 200,
  message: 'success',
  data: {
    'list|10': [{
      'id|+1': 1,
      'name': '@cname',
      'penName': '@cname',
      'novelCount|0-10': 1,
      'contact': '@phone',
      'description': '@cparagraph(1, 3)',
      'createTime': '@datetime'
    }],
    'total': 100
  }
});

// 作者列表（不分页，用于下拉选择）
Mock.mock(/\/author\/list$/, 'get', {
  code: 200,
  message: 'success',
  data: [{
    'id|+1': 1,
    'name': '@cname',
    'penName': '@cname',
    'contact': '@phone',
    'description': '@cparagraph(1, 3)'
  }]
});

// 新增/编辑分类
Mock.mock(/\/category/, 'post', {
  code: 200,
  message: '保存成功',
  data: null
});

// 新增/编辑作者
Mock.mock(/\/author/, 'post', {
  code: 200,
  message: '保存成功',
  data: null
});

// 删除分类
Mock.mock(/\/category\/\d+/, 'delete', {
  code: 200,
  message: '删除成功',
  data: null
});

// 删除作者
Mock.mock(/\/author\/\d+/, 'delete', {
  code: 200,
  message: '删除成功',
  data: null
});

Mock.mock(/\/novel/, 'post', {
  code: 200,
  message: '保存成功',
  data: null
});

// 评论列表
Mock.mock(/\/comment\/list/, 'get', function(options) {
  const params = new URLSearchParams(options.url.split('?')[1]);
  const status = params.get('status') || '';
  const query = params.get('query') || '';
  
  let list = Mock.mock({
    'list|10': [{
      'id|+1': 1,
      'novelId|1-100': 1,
      'novelName': '@ctitle(3, 10)',
      'userId|1-100': 1,
      'userName': '@cname',
      'content': '@cparagraph(1, 3)',
      'status': status || '@pick(["pending", "approved", "rejected"])',
      'createTime': '@datetime'
    }]
  }).list;

  // 如果有搜索关键词，过滤列表
  if (query) {
    list = list.filter(item => item.novelName.includes(query));
  }

  // 如果有状态筛选，过滤列表
  if (status) {
    list = list.filter(item => item.status === status);
  }

  return {
    code: 200,
    message: 'success',
    data: {
      list,
      total: list.length
    }
  };
});

// 审核通过评论
Mock.mock(/\/comment\/\d+\/approve/, 'post', {
  code: 200,
  message: '审核通过成功',
  data: null
});

// 审核拒绝评论
Mock.mock(/\/comment\/\d+\/reject/, 'post', {
  code: 200,
  message: '审核拒绝成功',
  data: null
});

// 删除评论
Mock.mock(/\/comment\/\d+/, 'delete', {
  code: 200,
  message: '删除成功',
  data: null
}); 